package com.aceitunaproject.webclient.client;

import com.aceitunaproject.shared.gamelement.Installation;
import com.aceitunaproject.shared.gamelement.Settlement;
import com.aceitunaproject.shared.gamelement.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.VerticalPanel;

public class OrdersPanel extends VerticalPanel {

	private static final long serialVersionUID = 1L;
	private MainAceitunaClient controller;


	public OrdersPanel(MainAceitunaClient controller) {
		this.controller = controller;

	}

	public void setForUnit(Unit unit) {

		this.clear();
		addButton("Refresh Map", EnumOrder.RefreshMap);
		addButton("Build Settlement", EnumOrder.BuildSettlement);
		addButton("Build Installation", EnumOrder.BuildInstallation);
		addButton("Attack Unit", EnumOrder.AttackUnit);
		addButton("Move Unit", EnumOrder.MoveUnit);

	}

	public void setForInstallation(Installation installation) {


		this.clear();
		addButton("Refresh Map", EnumOrder.RefreshMap);

	}

	public void setForSettlement(Settlement settlement) {


		this.clear();
		addButton("Refresh Map", EnumOrder.RefreshMap);
		addButton("Build Unit", EnumOrder.BuildUnit);

	}

	public void actionPerformed(EnumOrder e) {

		switch (e) {
		case RefreshMap:
			controller.orderedToRefreshMap();
			break;
		case Cancel:
			controller.orderedToCancel();
			break;
		case BuildSettlement:
			controller.orderedToBuildSettlement();
			break;
		case BuildInstallation:
			controller.orderedToBuildInstallation();
			break;
		case AttackUnit:
			controller.orderedToAttackWithUnit();
			break;
		case BuildUnit:
			controller.orderedToBuildUnit();
			break;
		case MoveUnit:
			controller.orderedToMoveUnit();
			break;
		default:
			break;
		}
	}

	private void addButton(String text, final EnumOrder action) {

		Button button = new Button(text);
		button.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				actionPerformed(action);

			}
		});
		this.add(button);
	}

	public void setForNothing() {


		this.clear();
		addButton("Refresh Map", EnumOrder.RefreshMap);

	}

	public void setForCancelOnly() {
		this.clear();
		addButton("Cancel", EnumOrder.Cancel);

	}

}
